package com.dc.controller;


import com.dc.annotation.Log;
import com.dc.common.ResponseResultVO;
import com.dc.entity.SysResource;
import com.dc.entity.ro.MenuRO;
import com.dc.entity.ro.SysResourceRO;
import com.dc.ro.PageRO;
import com.dc.service.SysResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 系统菜单
 */
@Api(tags = "后台-系统菜单接口(菜单、按钮、权限)")
@Controller
@RequestMapping(value = "/sys/resource")
@RestController
public class SysResourceController {

    @Resource
    private SysResourceService sysResourceService;

    @Log(title = "系统菜单", businessDesc = "新增菜单")
    @ApiOperation(value = "新增菜单", notes = "新增菜单")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResultVO insert(@RequestBody SysResourceRO sysResource) {
        return this.sysResourceService.insert(sysResource);
    }

    @Log(title = "系统菜单", businessDesc = "修改菜单")
    @ApiOperation(value = "修改菜单", notes = "修改菜单")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResultVO update(@RequestBody SysResourceRO sysResource) {
        return this.sysResourceService.update(sysResource);
    }

    @Log(title = "系统菜单", businessDesc = "删除菜单")
    @ApiOperation(value = "删除菜单", notes = "删除菜单")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResultVO delete(@RequestParam(name = "id") String id) {
        return this.sysResourceService.delete(id);
    }


    @ApiOperation(value = "查询菜单列表", notes = "查询菜单列表")
    @RequestMapping(value = "/selectSysResourceList", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResultVO<SysResource> selectSysResourceList(@RequestBody PageRO pageRO) {
        return this.sysResourceService.selectSysResourceList(pageRO);
    }


    @ApiOperation(value = "查询菜单树形列表", notes = "查询菜单树形列表")
    @RequestMapping(value = "/selectTreeList", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResultVO<SysResource> selectTreeList(@RequestBody(required = false) SysResourceRO ro) {
        return this.sysResourceService.selectTreeList(ro);
    }


    @ApiOperation(value = "菜单初始化", notes = "菜单初始化")
    @RequestMapping(value = "/menuInit", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResultVO<SysResource> menuInit() {
        return this.sysResourceService.menuInit();
    }


    @ApiOperation(value = "查询按钮列表", notes = "查询按钮列表")
    @RequestMapping(value = "/selectMenuBtnList", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResultVO<SysResource> selectMenuBtnList() {
        return sysResourceService.selectMenuBtnList();
    }

    @ApiOperation(value = "查询子集菜单", notes = "查询子集菜单")
    @RequestMapping(value = "/selectSysResourceByParentId", method = RequestMethod.GET)
    @ResponseBody
    public ResponseResultVO<SysResource> selectSysResourceByParentId(@RequestParam(required = false) Long parentId) {
        return this.sysResourceService.selectSysResourceByParentId(parentId);
    }


}
